import request from '@/utils/request'

const baseURL = '/personInfo'

// 更新密码
export const updatePassword = (user, passwordForm) => {
  return request.post(`${baseURL}/updatePassword?id=${user.id}`, {
    password: passwordForm.newPassword
  })
}

// 更改用户信息
export const changeUserInformation = (userInfoForm, user) =>
  request.post(`${baseURL}/updateUserInfo`, { ...userInfoForm, id: user.id })

// 获取账户余额
export const getMoney = (id) =>
  request.get(`${baseURL}/getMoney`, {
    params: {
      id
    }
  })

// 充值余额
export const addMoneys = (money, id) =>
  request.get(`${baseURL}/addMoney/${id}`, {
    params: {
      money
    }
  })

// 更新账户余额
export const updateMoney = (id, consumeMoney) =>
  request.get(`${baseURL}/updatemoney/${id}`, {
    params: {
      consumeMoney
    }
  })

// 获取用户商店列表
export const getAllShop = (user) => request.get(`${baseURL}?id=${user.id}`)

// 增加商店
export const addBusinessInfo = (user, businessInfoForm) =>
  request.post(`${baseURL}/addNewBusiness?id=${user.id}`, businessInfoForm)

// 获取商店信息
export const manageShop = (value, user) => {
  return request.get(`${baseURL}/${value.id}`, {
    params: {
      userId: user.id
    }
  })
}

// 更新商店信息
export const updateBusiness = (user, updateId, businessInfoForm) =>
  request.post(`${baseURL}/${user.id}?id=${updateId.value}`, businessInfoForm)

// 获取名字
export const getNameById = (id) => request.get(`${baseURL}/getNameById/${id}`)

// 获取购物车信息
export const getShopCardInfo = (userId) => request.get(`${baseURL}/getcartinformation/${userId}`)

// 将商品加入到购物车
export const addToCartByNewItem = (shopCard) => request.post(`${baseURL}/addtocart`, shopCard)

// 获取用户信息
export const getUserInfo = (id) => request.get(`${baseURL}/getUserInfo/${id}`)

// 订单完成添加
export const addOrderInfo = (orderItem) => request.post(`${baseURL}/addOrderInfo`, orderItem)

// 获取订单信息
export const getOrders = (userId, flag) =>
  request.get(`${baseURL}/getorders/${userId}`, {
    params: {
      flag
    }
  })
